import { mergeConfig, loadEnv } from 'vite';
import eslint from 'vite-plugin-eslint';
import baseConfig from './vite.config.base';
const root = process.cwd();

const env = loadEnv('development', root);

export default mergeConfig(
  {
    mode: 'development',
    server: {
      host: true,
      port: 8180,
      open: true,
      proxy: {
        '/api': {
          // target: 'https://vue.ruoyi.vip/prod-api',
          target: env.VITE_APP_BASE_API,
          changeOrigin: true,
          ws: true,
          rewrite: (path) => path.replace(new RegExp(`^/api`), ''),
          bypass(req, res) {
            console.log('请求', req.url);
            // console.log('响应', res);
            // 可选：用于调试，直接返回响应而不代理
            // return '/test-debug-response';
            return undefined; // 继续正常代理流程
          },
          // https is require secure=false
          secure: false,
        },
      },
      fs: {
        strict: true,
      },
    },
    plugins: [
      // eslint({
      //   cache: false,
      //   include: ['src/**/*.ts', 'src/**/*.tsx', 'src/**/*.vue'],
      //   exclude: ['node_modules'],
      // }),
    ],
  },
  baseConfig
);
